package day2.homework;


import java.io.*;

//复制一个1G左右的视频文件显示复制所花的时间 显示百分比  10%  20% ...100%成功
public class Work3 {
    public static void main(String[] args) {
        File f = new File("d://IO//video//DAXZ.mp4");
        try (
             FileInputStream fis = new FileInputStream(f);
             FileOutputStream fos = new FileOutputStream("d://IO//video//movie//newDAXZ.mp4");
             BufferedInputStream bis = new BufferedInputStream(fis);
             BufferedOutputStream bos = new BufferedOutputStream(fos);
        ){
            //定义视频总字节数
            long fileSize = f.length();
            //定义已读取字节数
            long totalReadSize = 0;
            int n = 1;
            long start = System.currentTimeMillis();
            byte[] bs = new byte[1024];
            int len = 0;
            while ((len = bis.read(bs)) != -1){
                totalReadSize += len;
                bos.write(bs,0,len);
                if (totalReadSize>=fileSize/10*n){
                    long mid = System.currentTimeMillis();
                    System.out.println("当前花费时间："+(mid-start)+"ms");
                    System.out.println("复制进度:"+(n*10)+"%");
                    n++;
                }
            }
            long end = System.currentTimeMillis();
            System.out.println("复制成功,耗时："+(end-start)+"ms");
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
